package com.igeek.boot.mapper;

import com.igeek.boot.entity.Role;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.Set;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author jwj
 * @since 2024-01-04
 */
@Mapper
public interface RoleMapper extends BaseMapper<Role> {
    @Select("select * from role r join user_role ur on r.id = ur.role_id where ur.user_id = #{userId}")
    @Results({
            @Result(id = true , column = "id" , property = "id"),
            @Result(column = "id" , property = "permissions" , javaType = Set.class,
                    many = @Many(select = "com.igeek.boot.mapper.PermissionMapper.findPermissionByRoleId"))
    })
    public Set<Role> findRoleByUserId(Integer userId);
}
